class Solution(object):
    def minAvailableDuration(self, slots1, slots2, duration):
        """
        :type slots1: List[List[int]]
        :type slots2: List[List[int]]
        :type duration: int
        :rtype: List[int]
        """
        slots1.sort()
        slots2.sort()
        left_index = 0
        right_index = 0
        while left_index < len(slots1) and right_index < len(slots2):
            if slots1[left_index][0] >= slots2[right_index][1]:
                right_index += 1
            else:
                if slots1[left_index][1] <= slots2[right_index][0]:
                    left_index += 1
                else:
                    start_time = max(slots1[left_index][0], slots2[right_index][0])
                    end_time = min(slots1[left_index][1], slots2[right_index][1])
                    if end_time - start_time >= duration:
                        return [start_time, start_time + duration]
                    else:
                        if slots1[left_index][1] == end_time:
                            left_index += 1
                        if slots2[right_index][1] == end_time:
                            right_index += 1
        return []
